<template>
  <el-container class="home-container">
    <!-- 头部区域 -->
    <el-header>
      <div>
        <img src="../assets/heima.png" alt="" />
        <span>商家后台管理系统</span>
      </div>
      <el-button type="warning" @click="logout">退出</el-button>
    </el-header>
    <!-- 主体区域 -->
    <el-container>
      <!-- 侧边栏导航 -->
      <el-aside width="200px">
        <el-menu
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b"
        >
          <!-- 一级导航 -->
<<<<<<< HEAD
          <el-submenu :index="item.id+''" v-for="item in menuList" :key="item.id">
=======
          <el-submenu
            :index="item.id + ''"
            v-for="item in menuList"
            :key="item.id"
          >
>>>>>>> home
            <!-- 一级导航模板 -->
            <template slot="title">
              <!-- 字体图标 -->
              <i class="el-icon-location"></i>
              <!-- 文本 -->
              <span>{{ item.authName }}</span>
            </template>
            <!-- 二级导航 -->
<<<<<<< HEAD
            <el-menu-item :index="secItem.id+''" v-for="secItem in item.children" :key="secItem.id">
=======
            <el-menu-item
              :index="secItem.id + ''"
              v-for="secItem in item.children"
              :key="secItem.id"
            >
>>>>>>> home
              <!-- 一级导航模板 -->
              <template slot="title">
                <!-- 字体图标 -->
                <i class="el-icon-location"></i>
                <!-- 文本 -->
                <span>{{ secItem.authName }}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 右边内容区域 -->
      <el-main>Main</el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  created() {
    this.getMenuList();
  },
  data() {
    return {
      menuList: [],
    };
  },
  methods: {
    // 退出按钮
    logout() {
      // 1 先清空保存的token值
      window.sessionStorage.clear();
      // 2 编程式跳转到login页面
      this.$router.push("/login");
    },
    // 发起侧边栏请求
    async getMenuList() {
      const { data: res } = await this.$http.get("menus");
      // 如果发起请求失败 终止函数 返回一个提示信息
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg);
      // 如果发起成功 把res里面的data值赋值给menuList
      this.menuList = res.data;
    },
  },
};
</script>

<style lang="less" scoped>
.home-container {
  height: 100%;
  .el-header {
    background-color: #373D41;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-left: 0;
    > div {
      display: flex;
      align-items: center;
      span {
        margin-left: 20px;
        color: #fff;
        font-size: 20px;
      }
    }
  }
  .el-aside {
    background-color: #333744;
  }
  .el-main {
    background-color: #eaedf1;
  }
}
</style>